﻿@model RTW.Model.SysUnit
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = "湖北省检察院档案管理系统 - 机构添加";
}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form asp-area="Unit" asp-controller="Home" asp-action="IndexFrom" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="DWMC">单位名称</label>
            <div class="layui-input-inline">
                <input asp-for="DWMC" type="text" lay-verify="required" placeholder="请输入单位名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="DWDM">单位代码</label>
            <div class="layui-input-inline">
                <input asp-for="DWDM" type="text" lay-verify="required" placeholder="请输入单位代码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="DWBZ">单位备注</label>
            <div class="layui-input-inline">
                <textarea asp-for="DWBZ" lay-verify="required" style="width: 400px; height: 150px;" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form">
            <label class="layui-form-label" asp-for="PID">上级单位</label>
            <div class="layui-input-inline">
                <select lay-verify="required" asp-for="PID" asp-items="@ViewBag.ulist">
                    <option value="">请选择上级单位</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="DWSX">单位顺序</label>
            <div class="layui-input-inline">
                <input asp-for="DWSX" type="text" lay-verify="required" placeholder="请输入顺序号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="DWZT">单位状态</label>
            <div class="layui-input-inline">
                <input asp-for="DWZT" type="checkbox" lay-verify="required" lay-filter="status" lay-skin="switch" lay-text="启用|禁用">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
        </div>
        <input type="hidden" asp-for="DWID" />
    </form>
</div>

@section scripts{
    <script>
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , layer = layui.layer

            //监听提交submit(layuiadmin-app-form-submit)
            form.on('submit(layuiadmin-app-form-submit)', function (d) {
                // console.log(data);
                var field = d.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                var dataform = $('form').serialize();
                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.ajax({
                    type: "POST",
                    url: "/Unit/Home/IndexFrom",
                    async: true,
                    data: d.field,
                    success: function (res) {
                        if (res.code == '0') {
                            parent.layer.close(index); //再执行关闭
                        }
                        res.success ? top.layer.msg(res.msg, { icon: 6, times: 2000 }): top.layer.msg(res.msg, { icon: 5, times: 2000 });
                    },
                    error: function (data) {

                    }
                });
                return false;
            });
        });
    </script>
}